package com.wenjie.shoprankmonitor;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

public class GetTaobaoResult {
	protected static String appkey = "12201364";
	protected static String secret = "89ec79f08a30ab437e0c8e8fc05d8349";
	
	public static String testUserGet(String q){
    	 TreeMap<String, String> apiparamsMap = new TreeMap<String, String>();
    	 apiparamsMap.put("format", "json");
    	 apiparamsMap.put("method", "taobao.items.get");
    	 apiparamsMap.put("sign_method","md5");
    	 apiparamsMap.put("app_key",appkey);
    	 apiparamsMap.put("page_size", "5");
    	 apiparamsMap.put("v", "2.0");
    	 String timestamp =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    	 apiparamsMap.put("timestamp",timestamp);
    //	 apiparamsMap.put("fields","num_iid, title, nick, pic_url, cid, price, type, delist_time, post_fee");
    	 apiparamsMap.put("fields","num_iid, title, nick, score");
    	 if(!q.equals(""))
    		 apiparamsMap.put("q",q);

    	 String sign = Util.md5Signature(apiparamsMap,secret);
    	 apiparamsMap.put("sign", sign);
    	 StringBuilder param = new StringBuilder();
    	 for (Iterator<Map.Entry<String, String>> it = apiparamsMap.entrySet()
    	 .iterator(); it.hasNext();) {
        	 Map.Entry<String, String> e = it.next();
        	 param.append("&").append(e.getKey()).append("=").append(e.getValue());
    	 }
    	 return param.toString().substring(1);
	}
}
